001 import java.io.*; 002 003 /** 004 * Default User interface for the Hangman game. Provides a console-based user interface. 005 * Obtains user guesses from the keyboard and displays a very simplistic view of the board. 006 * 007 */ 008 009 public class SimpleUI implements HangmanUI 010 { 011 /** the playing board */ 012 protected Board board; 013 /** the instance of game logic that will call us */ 014 private HangmanLogic parent; 015 /** input stream for the keyboard */ 016 private BufferedReader in; 017 018 /** Display a welcome message */ 019 public SimpleUI() 020 { 021 } 022 023 024 /** 025 * Save a reference to the instance of the Board. 026 */ 027 public void setBoard(Board theBoard) 028 { 029 } 030 031 032 /** 033 * Save a reference to the parent (an instance of HangmanLogic) 034 */ 035 public void setParent(HangmanLogic theParent) 036 { 037 } 038 039 040 /** 041 * Make the interface visible 042 */ 043 public void display() 044 { 045 // establish a keyboard reader 046 047 // Main event loop: loop forever 048 // get the player's move and process it 049 050 // if exception occurs display the exception message 051 052 } 053 054 /** 055 * Display that the player won the game. 056 */ 057 public void showWin() 058 { 059 } 060 061 /** 062 * Display that the player lost the game. 063 * Reveal the solution. 064 */ 065 public void showLose() 066 { 067 } 068 069 /** 070 * Display the current state of the board. 071 * Specifically, display the turn counter and 072 * display the board in some formatted manner. 073 */ 074 public void showBoard() 075 { 076 } 077 078 079 /** 080 * Asks the user for a move until the user enters a move that is valid. 081 */ 082 private char getMove() throws Exception 083 { 084 085 // Repeat until a valid move is entered 086 // Prompt for a move 087 // Read the move 088 089 // convert letter to upper case 090 // make sure move is only one letter 091 // if letter is not alphabetic then issue error message 092 093 // Return the move 094 return ' '; // stub implementation to avoid "missing return" error 095 } 096 097 /** 098 * Handle end of game, asking if the player wants another game 099 * If yes, start a new game, otherwise exit. 100 */ 101 public void playAgain() 102 { 103 // Prompt for another game 104 // Obtain user's choice 105 106 // if user doesn't want to continue, exit 107 // otherwise start a new game 108 109 } 110 111 112 }